---
# tasks to setup a planet server
#

- name: add planet group
  group: name=planet-user gid=104 system=yes state=present
  tags:
    - planet_server

- name: add planet user
  user: name=planet-user uid=104 group=planet-user home=/srv/planet comment="People Planet Eater" createhome=yes system=yes shell=/bin/bash
  tags:
    - planet_server

- name: add apache to planet group
  user: name=apache append=yes groups=planet-user
  tags:
    - planet_server

- name: install the planet packages
  package:  pkg={{item}} state=present
  with_items:
    - venus
  tags:
    - planet_server

- name: add base planet config directory
  file: path=/etc/planet state=directory owner=root group=root mode=0775
  tags:
    - planet_server

- name: copy the planet http config file
  template: src=planet.conf dest=/etc/httpd/conf.d/planet.conf
  tags:
    - planet_server

- name: copy the run planet-config script into /usr/local/bin
  copy: src=pull-run-planet-config.sh dest=/usr/local/bin/pull-run-planet-config.sh mode=755
  tags:
    - planet_server

- name: copy the planetconfigbuilder.py script into /usr/local/bin
  copy: src=planetconfigbuilder.py dest=/usr/local/bin/planetconfigbuilder.py mode=755
  tags:
    - planet_server

- name: create planet directory
  file: path={{ item }} state=directory owner=planet-user group=web mode=0775
  with_items:
    - /srv/planet
    - /srv/planet/site
    - /srv/planet/config

- name: check the selinux context of the planet dir
  command: matchpathcon "/srv/planet"
  register: gitcontext
  check_mode: no
  changed_when: false
  tags:
    - config
    - selinux
    - planet_server

- name: set the SELinux policy for the planet dir
  command: semanage fcontext -a -t httpd_sys_content_t "/srv/planet(/.*)?"
  when: gitcontext.stdout.find('httpd_sys_content_t') == -1
  tags:
    - config
    - selinux
    - planet_server

- name: copy the run-planet script
  copy: src=run-planet dest=/srv/planet/config/run-planet
  tags:
    - planet_server

#
# base planet.fedoraproject.org planet
#

- name: create planet directory (people)
  file: path={{ item }} state=directory owner=planet-user group=web mode=0775
  with_items:
    - /etc/planet/people
    - /srv/planet/config/people

- name: base planet config files
  copy: src=people_base_config dest=/etc/planet/people_base_config mode=0644 owner=root group=root
  tags:
    - planet_server

- name: copy the planet cron job (people)
  copy: src=planet-cron dest=/etc/cron.d/planet-cron
  tags:
    - planet_server

#
# design
#

- name: create planet directory (design)
  file: path={{ item }} state=directory owner=planet-user group=web mode=0775
  with_items:
    - /etc/planet/design
    - /srv/planet/config/design
    - /srv/planet/config/design/cache
    - /srv/planet/site/design

- name: copy the planet cron job (design)
  copy: src=sub-planets/design/planet-group.cron dest=/etc/cron.d/planet-design.cron
  tags:
    - planet_server

- name: copy the planet fpbulder.conf (design)
  copy: src=sub-planets/design/fpbuilder.conf dest=/etc/planet/design/fpbuilder.conf
  tags:
    - planet_server

- name: copy the planet base_config (design)
  copy: src=sub-planets/design/base_config dest=/etc/planet/design/base_config mode=0644 owner=root group=root
  tags:
    - planet_server

#
# desktop
#

- name: create planet directory (desktop)
  file: path={{ item }} state=directory owner=planet-user group=web mode=0775
  with_items:
    - /etc/planet/desktop
    - /srv/planet/config/desktop
    - /srv/planet/config/desktop/cache
    - /srv/planet/site/desktop

- name: copy the planet cron job (desktop)
  copy: src=sub-planets/desktop/planet-group.cron dest=/etc/cron.d/planet-desktop.cron
  tags:
    - planet_server

- name: copy the planet fpbulder.conf (desktop)
  copy: src=sub-planets/desktop/fpbuilder.conf dest=/etc/planet/desktop/fpbuilder.conf
  tags:
    - planet_server

- name: copy the planet base_config (desktop)
  copy: src=sub-planets/desktop/base_config dest=/etc/planet/desktop/base_config mode=0644 owner=root group=root
  tags:
    - planet_server

#
# edited
#

- name: create planet directory (edited)
  file: path={{ item }} state=directory owner=planet-user group=web mode=0775
  with_items:
    - /etc/planet/edited
    - /srv/planet/config/edited
    - /srv/planet/config/edited/cache
    - /srv/planet/site/edited

- name: copy the planet cron job (edited)
  copy: src=sub-planets/edited/planet-group.cron dest=/etc/cron.d/planet-edited.cron
  tags:
    - planet_server

- name: copy the planet fpbulder.conf (edited)
  copy: src=sub-planets/edited/fpbuilder.conf dest=/etc/planet/edited/fpbuilder.conf
  tags:
    - planet_server

- name: copy the planet base_config (edited)
  copy: src=sub-planets/edited/base_config dest=/etc/planet/edited/base_config mode=0644 owner=root group=root
  tags:
    - planet_server

#
# people
#

- name: create planet directory (people)
  file: path={{ item }} state=directory owner=planet-user group=web mode=0775
  with_items:
    - /etc/planet/people
    - /srv/planet/config/people
    - /srv/planet/config/people/cache
    - /srv/planet/site/people

- name: copy templates (people)
  copy: src=sub-planets/people/{{ item }} dest=/srv/planet/config/people/ owner=planet-user group=planet-user
  with_items:
  - templates
  tags:
    - planet_server

- name: copy the css and images (people)
  synchronize: src=sub-planets/people/{{ item }}/ dest=/srv/planet/site/{{ item }}/
  with_items:
  - css-v2
  - images-v2
  tags:
    - planet_server

- name: copy the planet fpbulder.conf (people)
  copy: src=fpbuilder.conf dest=/etc/planet/fpbuilder.conf
  tags:
    - planet_server

#
# security
#

- name: create planet directory (security)
  file: path={{ item }} state=directory owner=planet-user group=web mode=0775
  with_items:
    - /etc/planet/security
    - /srv/planet/config/security
    - /srv/planet/config/security/cache
    - /srv/planet/site/security

- name: copy the planet cron job (security)
  copy: src=sub-planets/security/planet-group.cron dest=/etc/cron.d/planet-security.cron
  tags:
    - planet_server

- name: copy the planet fpbulder.conf (security)
  copy: src=sub-planets/security/fpbuilder.conf dest=/etc/planet/security/fpbuilder.conf
  tags:
    - planet_server

- name: copy the planet base_config (security)
  copy: src=sub-planets/security/base_config dest=/etc/planet/security/base_config mode=0644 owner=root group=root
  tags:
    - planet_server

#
# summer-coding
#

- name: create planet directory (summer-coding)
  file: path={{ item }} state=directory owner=planet-user group=web mode=0775
  with_items:
    - /etc/planet/summer-coding
    - /srv/planet/config/summer-coding
    - /srv/planet/config/summer-coding/cache
    - /srv/planet/site/summer-coding

- name: copy the planet cron job (summer-coding)
  copy: src=sub-planets/summer-coding/planet-group.cron dest=/etc/cron.d/planet-summer-coding.cron
  tags:
    - planet_server

- name: copy the planet fpbulder.conf (summer-coding)
  copy: src=sub-planets/summer-coding/fpbuilder.conf dest=/etc/planet/summer-coding/fpbuilder.conf
  tags:
    - planet_server

- name: copy the planet base_config (summer-coding)
  copy: src=sub-planets/summer-coding/base_config dest=/etc/planet/summer-coding/base_config mode=0644 owner=root group=root
  tags:
    - planet_server
#
#
# QA
#

- name: create planet directory (quality)
  file: path={{ item }} state=directory owner=planet-user group=web mode=0775
  with_items:
    - /etc/planet/quality
    - /srv/planet/config/quality
    - /srv/planet/config/quality/cache
    - /srv/planet/site/quality

- name: copy the planet cron job (quality)
  copy: src=sub-planets/quality/planet-group.cron dest=/etc/cron.d/planet-quality.cron
  tags:
    - planet_server

- name: copy the planet fpbulder.conf (quality)
  copy: src=sub-planets/quality/fpbuilder.conf dest=/etc/planet/quality/fpbuilder.conf
  tags:
    - planet_server

- name: copy the planet base_config (quality)
  copy: src=sub-planets/quality/base_config dest=/etc/planet/quality/base_config mode=0644 owner=root group=root
  tags:
    - planet_server
